


function(ukui_add_wayland_client_protocol out_var)
    # Parse arguments
    set(oneValueArgs PROTOCOL)
    cmake_parse_arguments(ARGS "" "${oneValueArgs}" "" ${ARGN})

    get_filename_component(_infile ${ARGS_PROTOCOL} ABSOLUTE)
    get_filename_component(_base_name ${_infile} NAME_WE)

    set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_base_name}.h")
    set(_code "${CMAKE_CURRENT_BINARY_DIR}/${_base_name}.cpp")
    set(_wayland_client_header "${CMAKE_CURRENT_BINARY_DIR}/wayland-${_base_name}-client-protocol.h")
    set(_wayland_code "${CMAKE_CURRENT_BINARY_DIR}/wayland-${_base_name}-protocol.c")

    set_source_files_properties(${_header} ${_code} ${_wayland_client_header} ${_wayland_code} GENERATED)
    set_property(SOURCE ${_header} ${_code} ${_wayland_client_header} ${_wayland_code} PROPERTY SKIP_AUTOMOC ON)

    add_custom_command(OUTPUT "${_header}" "${_wayland_client_header}" "${_wayland_code}" "${_code}"
        COMMAND ukuiwaylandscanner ${_infile} ${CMAKE_CURRENT_BINARY_DIR}
        DEPENDS ${_infile} VERBATIM)


    if (TARGET ${out_var})
        target_sources(${target_or_sources_var} ${_wayland_code} ${_code})
    else()
        list(APPEND ${out_var} ${_wayland_code} ${_code})
        set(${out_var} ${${out_var}} PARENT_SCOPE)
    endif()

    set(${out_var} ${${out_var}} PARENT_SCOPE)
endfunction()

set(WAYLAND_PROTOCOL_SRCS)
ukui_add_wayland_client_protocol(WAYLAND_PROTOCOL_SRCS
    PROTOCOL ${CMAKE_CURRENT_SOURCE_DIR}/ukui-window-management.xml
)

add_executable(ukuiwaylandprop
    main_prop.cpp
    ukuiwindow.cpp
    ukuiwindowmanager.cpp
    ukuiwindowpicker.cpp
    ${WAYLAND_PROTOCOL_SRCS}
)

add_executable(ukuidebugconsole
    main_debugconsole.cpp
    ukuidebugconsole.cpp
    ukuiwindow.cpp
    ukuiwindowmanager.cpp
    ${WAYLAND_PROTOCOL_SRCS}
)

target_link_libraries(ukuiwaylandprop
    Qt${QT_VERSION_MAJOR}::Widgets
    ukui-wayland-client
)

target_link_libraries(ukuidebugconsole
    Qt${QT_VERSION_MAJOR}::Widgets
    ukui-wayland-client
)

target_include_directories(ukuiwaylandprop
    PRIVATE
    ${CMAKE_CURRENT_BINARY_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}/../ukuiwaylandclient
    ${CMAKE_CURRENT_SOURCE_DIR}/../ukuiwaylandclient
)

target_include_directories(ukuidebugconsole
    PRIVATE
    ${CMAKE_CURRENT_BINARY_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}/../ukuiwaylandclient
    ${CMAKE_CURRENT_SOURCE_DIR}/../ukuiwaylandclient
)

install(TARGETS ukuiwaylandprop
    RUNTIME DESTINATION bin
)

install(TARGETS ukuidebugconsole
    RUNTIME DESTINATION bin
)
